const util = require('../../utils/util.js')
const app = getApp();
// const {getTime} = require('../../api/geData.js')
Component({
  properties: {
    itemData: null,
    percentData:null,
    isCourse:null
  },
  data:{
    isCourse:''
  },
  methods:{
    gotoPage(e) {  // 课程列表跳转函数
      if (app.globalData.stopMoreClick) return
      app.globalData.stopMoreClick = true
      let itemData = this.properties.itemData
      // console.log(itemData)
      const { courseid, formalclassid, classid, noticeId, packId, coursename, formalClassName, intentClassName, status, begintime, endtime, show, selTimeBegin, selTimeEnd,classsituation,activityName } = itemData
      const noticeType = itemData.noticeType ? itemData.noticeType : 0
      // console.log('noticeType')
      // console.log(noticeType)
      // console.log(itemData.noticeType)
      /* 参数处理，勿动 */
      const startTime = util.formatTime(begintime && begintime || selTimeBegin, 1).split(' ')[0]
      const endTime = util.formatTime(endtime && endtime || selTimeEnd, 1).split(' ')[0]
      const passData = {
        statusId: status,
        courseName: coursename,
        formalClassName: formalClassName,
        intentClassName: intentClassName,
        startTime: startTime,
        endTime: endTime,
        time: startTime + '至' + endTime,
        courseId: courseid,
        classid: classid,
        noticeId:noticeId,
        packId: packId,
        formalclassid: formalclassid,
        isJobCourse: (noticeType == 1 && true || false),
        classsituation:classsituation,
        selTimeBegin: selTimeBegin,
        selTimeEnd: selTimeEnd,
        activityName: activityName
      }
      wx.setStorageSync("passData", passData)
      
      /* 页面传参 */
      let paramsUrl = `?courseid=${courseid}&formalclassid=${formalclassid}&classid=${classid}&coursename=${coursename}&status=${status}&begintime=${begintime}&endtime=${endtime}`
      if (show){
        paramsUrl = `?courseid=${courseid}&formalclassid=${formalclassid}&classid=${classid}&coursename=${coursename}&status=${status}&begintime=${begintime}&endtime=${endtime}`
      }
      switch (status) {
        case '0': //未开始
          if (noticeId){
            wx.navigateTo({
              url: `/pages/detail/detailGrade/detailGrade${paramsUrl}`
            })
          } else {
            wx.navigateTo({
              url: `/pages/detail/detailGrade/detailGrade?status=2`
            })
          }
          break;
        case '1': //未确认变已报名
          // let grade= wx.getStorageSync('agreeGrade'),
          //   url = null
          // if (passData.isJobCourse){
          //   url = `/pages/period/selectPeriod/selectPeriod?showQuick=0`
          // } else {
          //   if (grade.packId == packId && grade.courseId == courseid && grade.noticeId == noticeId) {
          //     url = `/pages/period/selectPeriod/selectPeriod?showQuick=0&classsituation=` + classsituation
          //   } else {
          //     url = `/pages/detail/agreeGrade/agreeGrade`
          //   }
          // }
          // wx.navigateTo({
          //   url: url
          // })
          wx.navigateTo({
            url: `/pages/detail/waitGrade/waitGrade?showTextIndex=3&showBtn=0'`,
          })
          
          break;
        case '2': //已确认变已反馈时间
          wx.navigateTo({
            url: `/pages/detail/waitGrade/waitGrade?showTextIndex=2&showBtn=0'`,
          })
          break;
        case '3': //待排班 变已排班
          // wx.navigateTo({
          //   url: '/pages/detail/waitGrade/waitGrade?showTextIndex=0&showBtn=0'
          // })
          wx.navigateTo({
            url: `/pages/period/confirmPeriod/confirmPeriod`
          })
          break;
        case '4': //已排班 弃用
          // wx.navigateTo({
          //   url: `/pages/period/confirmPeriod/confirmPeriod`
          // })
          break;
        case '5': //待开班 弃用
          // wx.navigateTo({
          //   url: '/pages/detail/waitGrade/waitGrade?showTextIndex=1&showBtn=0'
          // })
          break;
        case '6': //已开班
          wx.navigateTo({
            url: `/pages/period/coursePeriod/coursePeriod`
          })
          break;
        case '7': //已结课
          // console.log('已结课')
          wx.setStorageSync('sevenData',{
            status: status,
            coursename: coursename
          })
          wx.request({
            url: app.globalData.baseUrl + '/quesSurvey/findByStudentIdByformalClassId' + '/' + wx.getStorageSync('userInfo').cluesOrStuId + '/' + passData.formalclassid,
            method: 'POST',
            header: {
              "Content-Type": "application/x-www-form-urlencoded"
            },
            success(res) {
              if (res.data.code == 0) {
                let isReply = res.data.data.sendQuesSurvey.isReply
                if(isReply!='1')
                {
                  wx.navigateTo({
                    url: `/pages/questionSurvey/questionSurvey?stuId=${wx.getStorageSync('userInfo').cluesOrStuId}&formalClassId=${passData.formalclassid}`
                  })
                }else{
                  wx.navigateTo({
                    url: `/pages/detail/detailGrade/detailGrade?status=${status}&coursename=${coursename}`
                  })
                }
              }
            }
          })
          break;
      }
      if(status==6)
      {
        wx.request({
          url: app.globalData.baseUrl + '/calendars/confirmTimeTable',
          method: 'POST',
          header: {
            "Content-Type": "application/json"
          },
          data: {
            "stuId": wx.getStorageSync('userInfo').cluesOrStuId,
            "formalClassId": passData.formalclassid,
          },
          success(res) {

          }
        })
      }
    },
    checkMark(){
      let itemData = this.properties.itemData;
      const { formalclassid } = itemData;
      let user = wx.getStorageSync('userInfo')
      wx.navigateTo({
        url: `/pages/scoreResult/scoreResult?stuId=${user.cluesOrStuId}&formalclassid=${itemData.formalclassid}&hcId=${itemData.hcId}`
      })
    },
    // 提交就业素材页面
    submitMaterial() {
      wx.navigateTo({
        url: `/pages/materialData/materialData`,
      })
    },
  },
  ready(){
    let percentData=this.properties.percentData,
      isCourse = this.properties.isCourse
    this.setData({
      percentData:percentData,
      isCourse:isCourse
    })
  }
})